package com.zj.aspects;

import com.alibaba.nacos.shaded.com.google.gson.Gson;
import com.zj.web.bean.RedPacketActivityDTO;
import com.zj.web.bean.UserRedPacketDTO;
import lombok.extern.java.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Component;

@Component
@Log
public class JmsRedPacketMessageProducter {
    //配置队列名
    @Value("${spring.activemq.redpacketQueue}")
    private String redpacketQueue;

    @Autowired
    private JmsTemplate jmsTemplate; //Jms的操作模板  类比jdbcTemplate

    public void sendMessage(UserRedPacketDTO UserRedPacketDTO){
        Gson gson = new Gson();
        //将对象中null值的数据排除掉

        String json = gson.toJson(UserRedPacketDTO);
        //发送消息到队列
        jmsTemplate.convertAndSend(redpacketQueue,json);
        log.info("发送消息到队列：" + redpacketQueue + "，消息内容：" + json);
    }
}
